package test.org.example.java.nio;

import java.nio.ByteBuffer;
import java.util.concurrent.TimeUnit;

import sun.nio.ch.DirectBuffer;

public class DirectByteBufferCleaner {
  public static void sleep(long i) {
    try {
      TimeUnit.SECONDS.sleep(i);
    } catch (Exception ignore) {
    }
  }

  public static void main(String[] args) throws Exception {
    ByteBuffer buffer = ByteBuffer.allocateDirect(1024 * 1024 * 200);
    System.out.println("start");
    sleep(10);
    if (buffer.isDirect()) {
      ((DirectBuffer) buffer).cleaner().clean();
    }
    System.out.println("end");
    sleep(10);
  }
}
